package com.guodu.dao.impl;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.guodu.base.BaseDao;
import com.guodu.dao.MaterialChaoshiDao;
import com.guodu.entity.MaterialChaoshi;
import com.guodu.entity.MaterialchaoshiStatus;
import com.guodu.entity.Units;
import com.guodu.vo.MaterialChaoshiQueryVo;

@Repository("materialChaoshiDao")
public class MaterialChaoshiDaoImpl extends BaseDao implements MaterialChaoshiDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<MaterialChaoshi> findByVo(MaterialChaoshiQueryVo materialChaoshiQueryVo,Units units,
			int curPage, int pageSize) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("from MaterialChaoshi m where 1=1");
		if(materialChaoshiQueryVo!=null){
			if(materialChaoshiQueryVo.getDrawingnum()!=null&&materialChaoshiQueryVo.getDrawingnum().trim().length()>0){
				hql.append(" and m.drawingnum like '%"+materialChaoshiQueryVo.getDrawingnum()+"%'");
			}
			if(materialChaoshiQueryVo.getFunitsId()!=null){
				hql.append(" and exists(select 1 from Units u where u.unitsId=m.unitsId and u.funitsId="+materialChaoshiQueryVo.getFunitsId()+")");
			}
			if(materialChaoshiQueryVo.getMaterialCode()!=null&&materialChaoshiQueryVo.getMaterialCode().trim().length()>0){
				hql.append(" and materialCode like '%"+materialChaoshiQueryVo.getMaterialCode()+"%'");
			}
			if(materialChaoshiQueryVo.getMaterialName()!=null&&materialChaoshiQueryVo.getMaterialName().trim().length()>0){
				hql.append(" and materialName like '%"+materialChaoshiQueryVo.getMaterialName()+"%'");
			}
			if(materialChaoshiQueryVo.getSjBeginDate()!=null&&materialChaoshiQueryVo.getSjBeginDate().trim().length()>0){
				hql.append(" and shelvesTime >= TO_DATE('"+materialChaoshiQueryVo.getSjBeginDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSjEndDate()!=null&&materialChaoshiQueryVo.getSjEndDate().trim().length()>0){
				hql.append(" and shelvesTime <= TO_DATE('"+materialChaoshiQueryVo.getSjEndDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSpecifications()!=null&&materialChaoshiQueryVo.getSpecifications().trim().length()>0){
				hql.append(" and specifications like '%"+materialChaoshiQueryVo.getSpecifications()+"%'");
			}
			if(materialChaoshiQueryVo.getSupplier()!=null&&materialChaoshiQueryVo.getSupplier().trim().length()>0){
				hql.append(" and supplier like '%"+materialChaoshiQueryVo.getSupplier()+"%'");
			}
			if(materialChaoshiQueryVo.getTexture()!=null&&materialChaoshiQueryVo.getTexture().trim().length()>0){
				hql.append(" and texture like '%"+materialChaoshiQueryVo.getTexture()+"%'");
			}
			if(materialChaoshiQueryVo.getUnitsId()!=null){
				hql.append(" and m.unitsId="+materialChaoshiQueryVo.getUnitsId());
			}
			if(materialChaoshiQueryVo.getCreateBeginTime()!=null&&materialChaoshiQueryVo.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+materialChaoshiQueryVo.getCreateBeginTime()+ " 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getCreateEndTime()!=null&&materialChaoshiQueryVo.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+materialChaoshiQueryVo.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getChaoshiBeginTime()!=null&&materialChaoshiQueryVo.getChaoshiBeginTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') >= TO_DATE('"+materialChaoshiQueryVo.getChaoshiBeginTime()+ "','yyyy-mm')");
			}
			if(materialChaoshiQueryVo.getChaoshiEndTime()!=null&&materialChaoshiQueryVo.getChaoshiEndTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') <= TO_DATE('"+materialChaoshiQueryVo.getChaoshiEndTime()+"','yyyy-mm')");
			}
			
			if(materialChaoshiQueryVo.getStatus()!=null&&materialChaoshiQueryVo.getStatus().trim().length()>0&&!materialChaoshiQueryVo.getStatus().equals("5")){
				hql.append(" and status ="+materialChaoshiQueryVo.getStatus());
			}
		}
		if(units==null){
			hql.append(" and status=1");
		}
		hql.append(" order by chaoshiId desc");
		return super.findPages(hql.toString(), curPage, pageSize);
	}

	@Override
	public int findSizeByVo(
			MaterialChaoshiQueryVo materialChaoshiQueryVo,Units units) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("select count(*) from MaterialChaoshi m where 1=1");
		if(materialChaoshiQueryVo!=null){
			if(materialChaoshiQueryVo.getDrawingnum()!=null&&materialChaoshiQueryVo.getDrawingnum().trim().length()>0){
				hql.append(" and m.drawingnum like '%"+materialChaoshiQueryVo.getDrawingnum()+"%'");
			}
			if(materialChaoshiQueryVo.getFunitsId()!=null){
				hql.append(" and exists(select 1 from Units u where u.unitsId=m.unitsId and u.funitsId="+materialChaoshiQueryVo.getFunitsId()+")");
			}
			if(materialChaoshiQueryVo.getMaterialCode()!=null&&materialChaoshiQueryVo.getMaterialCode().trim().length()>0){
				hql.append(" and materialCode like '%"+materialChaoshiQueryVo.getMaterialCode()+"%'");
			}
			if(materialChaoshiQueryVo.getMaterialName()!=null&&materialChaoshiQueryVo.getMaterialName().trim().length()>0){
				hql.append(" and materialName like '%"+materialChaoshiQueryVo.getMaterialName()+"%'");
			}
			if(materialChaoshiQueryVo.getSjBeginDate()!=null&&materialChaoshiQueryVo.getSjBeginDate().trim().length()>0){
				hql.append(" and shelvesTime >= TO_DATE('"+materialChaoshiQueryVo.getSjBeginDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSjEndDate()!=null&&materialChaoshiQueryVo.getSjEndDate().trim().length()>0){
				hql.append(" and shelvesTime <= TO_DATE('"+materialChaoshiQueryVo.getSjEndDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSpecifications()!=null&&materialChaoshiQueryVo.getSpecifications().trim().length()>0){
				hql.append(" and specifications like '%"+materialChaoshiQueryVo.getSpecifications()+"%'");
			}
			if(materialChaoshiQueryVo.getSupplier()!=null&&materialChaoshiQueryVo.getSupplier().trim().length()>0){
				hql.append(" and supplier like '%"+materialChaoshiQueryVo.getSupplier()+"%'");
			}
			if(materialChaoshiQueryVo.getTexture()!=null&&materialChaoshiQueryVo.getTexture().trim().length()>0){
				hql.append(" and texture like '%"+materialChaoshiQueryVo.getTexture()+"%'");
			}
			if(materialChaoshiQueryVo.getUnitsId()!=null){
				hql.append(" and unitsId="+materialChaoshiQueryVo.getUnitsId());
			}
			if(materialChaoshiQueryVo.getCreateBeginTime()!=null&&materialChaoshiQueryVo.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+materialChaoshiQueryVo.getCreateBeginTime()+ " 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getCreateEndTime()!=null&&materialChaoshiQueryVo.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+materialChaoshiQueryVo.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getStatus()!=null&&materialChaoshiQueryVo.getStatus().trim().length()>0&&!materialChaoshiQueryVo.getStatus().equals("5")){
				hql.append(" and status ="+materialChaoshiQueryVo.getStatus());
			}
			if(materialChaoshiQueryVo.getChaoshiBeginTime()!=null&&materialChaoshiQueryVo.getChaoshiBeginTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') >= TO_DATE('"+materialChaoshiQueryVo.getChaoshiBeginTime()+ "','yyyy-mm')");
			}
			if(materialChaoshiQueryVo.getChaoshiEndTime()!=null&&materialChaoshiQueryVo.getChaoshiEndTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') <= TO_DATE('"+materialChaoshiQueryVo.getChaoshiEndTime()+"','yyyy-mm')");
			}
			
		}
		if(units==null){
			hql.append(" and status=1");
		}
		return super.findInt(hql.toString());
	}

	@Override
	public MaterialChaoshi findById(String id) {
		// TODO Auto-generated method stub
		return (MaterialChaoshi) super.findById(MaterialChaoshi.class, id);
	}

	@Override
	public void del(String id) {
		// TODO Auto-generated method stub
		super.delete(MaterialChaoshi.class, id);
	}

	@Override
	public void delByIds(String[] ids) {
		// TODO Auto-generated method stub
		super.deleteAllById(MaterialChaoshi.class, ids);
	}

	@Override
	public void save(MaterialChaoshi entity) {
		// TODO Auto-generated method stub
		entity.setChaoshiId("1");
		entity.setCreateTime(Calendar.getInstance().getTime());
		super.save(entity);
	}

	@Override
	public void examine(String ids, Long status) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("update MaterialChaoshi set status =");
		hql.append(status);
		hql.append(" where chaoshiId in (");
		hql.append(ids);
		hql.append(")");
		super.executeUpdate(hql.toString());
	}

	@Override
	public void update(MaterialChaoshi entity) {
		// TODO Auto-generated method stub
		super.update(entity);
	}

	@Override
	public void changeStatus(List<MaterialchaoshiStatus> entities) {
		// TODO Auto-generated method stub
		super.saveAll(entities);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MaterialchaoshiStatus> findStatus(String id) {
		// TODO Auto-generated method stub
		return super.findByProperty(MaterialchaoshiStatus.class, "materialId", id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MaterialChaoshi> findAllByVo(
			MaterialChaoshiQueryVo materialChaoshiQueryVo,Units units) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("from MaterialChaoshi m where 1=1");
		if(materialChaoshiQueryVo!=null){
			if(materialChaoshiQueryVo.getDrawingnum()!=null&&materialChaoshiQueryVo.getDrawingnum().trim().length()>0){
				hql.append(" and m.drawingnum like '%"+materialChaoshiQueryVo.getDrawingnum()+"%'");
			}
			if(materialChaoshiQueryVo.getFunitsId()!=null){
				hql.append(" and exists(select 1 from Units u where u.unitsId=m.unitsId and u.funitsId="+materialChaoshiQueryVo.getFunitsId()+")");
			}
			if(materialChaoshiQueryVo.getMaterialCode()!=null&&materialChaoshiQueryVo.getMaterialCode().trim().length()>0){
				hql.append(" and materialCode like '%"+materialChaoshiQueryVo.getMaterialCode()+"%'");
			}
			if(materialChaoshiQueryVo.getMaterialName()!=null&&materialChaoshiQueryVo.getMaterialName().trim().length()>0){
				hql.append(" and materialName like '%"+materialChaoshiQueryVo.getMaterialName()+"%'");
			}
			if(materialChaoshiQueryVo.getSjBeginDate()!=null&&materialChaoshiQueryVo.getSjBeginDate().trim().length()>0){
				hql.append(" and shelvesTime >= TO_DATE('"+materialChaoshiQueryVo.getSjBeginDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSjEndDate()!=null&&materialChaoshiQueryVo.getSjEndDate().trim().length()>0){
				hql.append(" and shelvesTime <= TO_DATE('"+materialChaoshiQueryVo.getSjEndDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSpecifications()!=null&&materialChaoshiQueryVo.getSpecifications().trim().length()>0){
				hql.append(" and specifications like '%"+materialChaoshiQueryVo.getSpecifications()+"%'");
			}
			if(materialChaoshiQueryVo.getSupplier()!=null&&materialChaoshiQueryVo.getSupplier().trim().length()>0){
				hql.append(" and supplier like '%"+materialChaoshiQueryVo.getSupplier()+"%'");
			}
			if(materialChaoshiQueryVo.getTexture()!=null&&materialChaoshiQueryVo.getTexture().trim().length()>0){
				hql.append(" and texture like '%"+materialChaoshiQueryVo.getTexture()+"%'");
			}
			if(materialChaoshiQueryVo.getUnitsId()!=null){
				hql.append(" and unitsId="+materialChaoshiQueryVo.getUnitsId());
			}
			if(materialChaoshiQueryVo.getCreateBeginTime()!=null&&materialChaoshiQueryVo.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+materialChaoshiQueryVo.getCreateBeginTime()+ " 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getCreateEndTime()!=null&&materialChaoshiQueryVo.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+materialChaoshiQueryVo.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getStatus()!=null&&materialChaoshiQueryVo.getStatus().trim().length()>0&&!materialChaoshiQueryVo.getStatus().equals("5")){
				hql.append(" and status ="+materialChaoshiQueryVo.getStatus());
			}
			if(materialChaoshiQueryVo.getChaoshiBeginTime()!=null&&materialChaoshiQueryVo.getChaoshiBeginTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') >= TO_DATE('"+materialChaoshiQueryVo.getChaoshiBeginTime()+ "','yyyy-mm')");
			}
			if(materialChaoshiQueryVo.getChaoshiEndTime()!=null&&materialChaoshiQueryVo.getChaoshiEndTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') <= TO_DATE('"+materialChaoshiQueryVo.getChaoshiEndTime()+"','yyyy-mm')");
			}
			
		}
		if(units==null){
			hql.append("and status=2");
		}
		hql.append("order by createTime desc");
		return super.find(hql.toString());
	}

	@Override
	public BigDecimal findAllMoney(MaterialChaoshiQueryVo materialChaoshiQueryVo,
			Units units) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("select sum(shelvesMoney) from MaterialChaoshi m where 1=1");
		if(materialChaoshiQueryVo!=null){
			if(materialChaoshiQueryVo.getDrawingnum()!=null&&materialChaoshiQueryVo.getDrawingnum().trim().length()>0){
				hql.append(" and m.drawingnum like '%"+materialChaoshiQueryVo.getDrawingnum()+"%'");
			}
			if(materialChaoshiQueryVo.getFunitsId()!=null){
				hql.append(" and exists(select 1 from Units u where u.unitsId=m.unitsId and u.funitsId="+materialChaoshiQueryVo.getFunitsId()+")");
			}
			if(materialChaoshiQueryVo.getMaterialCode()!=null&&materialChaoshiQueryVo.getMaterialCode().trim().length()>0){
				hql.append(" and materialCode like '%"+materialChaoshiQueryVo.getMaterialCode()+"%'");
			}
			if(materialChaoshiQueryVo.getMaterialName()!=null&&materialChaoshiQueryVo.getMaterialName().trim().length()>0){
				hql.append(" and materialName like '%"+materialChaoshiQueryVo.getMaterialName()+"%'");
			}
			if(materialChaoshiQueryVo.getSjBeginDate()!=null&&materialChaoshiQueryVo.getSjBeginDate().trim().length()>0){
				hql.append(" and shelvesTime >= TO_DATE('"+materialChaoshiQueryVo.getSjBeginDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSjEndDate()!=null&&materialChaoshiQueryVo.getSjEndDate().trim().length()>0){
				hql.append(" and shelvesTime <= TO_DATE('"+materialChaoshiQueryVo.getSjEndDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSpecifications()!=null&&materialChaoshiQueryVo.getSpecifications().trim().length()>0){
				hql.append(" and specifications like '%"+materialChaoshiQueryVo.getSpecifications()+"%'");
			}
			if(materialChaoshiQueryVo.getSupplier()!=null&&materialChaoshiQueryVo.getSupplier().trim().length()>0){
				hql.append(" and supplier like '%"+materialChaoshiQueryVo.getSupplier()+"%'");
			}
			if(materialChaoshiQueryVo.getTexture()!=null&&materialChaoshiQueryVo.getTexture().trim().length()>0){
				hql.append(" and texture like '%"+materialChaoshiQueryVo.getTexture()+"%'");
			}
			if(materialChaoshiQueryVo.getUnitsId()!=null){
				hql.append(" and unitsId="+materialChaoshiQueryVo.getUnitsId());
			}
			if(materialChaoshiQueryVo.getCreateBeginTime()!=null&&materialChaoshiQueryVo.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+materialChaoshiQueryVo.getCreateBeginTime()+ " 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getCreateEndTime()!=null&&materialChaoshiQueryVo.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+materialChaoshiQueryVo.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getStatus()!=null&&materialChaoshiQueryVo.getStatus().trim().length()>0&&!materialChaoshiQueryVo.getStatus().equals("5")){
				hql.append(" and status ="+materialChaoshiQueryVo.getStatus());
			}
			if(materialChaoshiQueryVo.getChaoshiBeginTime()!=null&&materialChaoshiQueryVo.getChaoshiBeginTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') >= TO_DATE('"+materialChaoshiQueryVo.getChaoshiBeginTime()+ "','yyyy-mm')");
			}
			if(materialChaoshiQueryVo.getChaoshiEndTime()!=null&&materialChaoshiQueryVo.getChaoshiEndTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') <= TO_DATE('"+materialChaoshiQueryVo.getChaoshiEndTime()+"','yyyy-mm')");
			}
			
		}
		if(units==null){
			hql.append(" and status=1");
		}
		hql.append(" order by createTime desc");
		return super.findDouble(hql.toString());
	}

	@Override
	public boolean examinAll(MaterialChaoshiQueryVo materialChaoshiQueryVo,
			Units units) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("update MaterialChaoshi m set status=1 where status=0  ");
		if(materialChaoshiQueryVo!=null){
			if(materialChaoshiQueryVo.getDrawingnum()!=null&&materialChaoshiQueryVo.getDrawingnum().trim().length()>0){
				hql.append(" and m.drawingnum like '%"+materialChaoshiQueryVo.getDrawingnum()+"%'");
			}
			if(materialChaoshiQueryVo.getFunitsId()!=null){
				hql.append(" and exists(select 1 from Units u where u.unitsId=m.unitsId and u.funitsId="+materialChaoshiQueryVo.getFunitsId()+")");
			}
			if(materialChaoshiQueryVo.getMaterialCode()!=null&&materialChaoshiQueryVo.getMaterialCode().trim().length()>0){
				hql.append(" and materialCode like '%"+materialChaoshiQueryVo.getMaterialCode()+"%'");
			}
			if(materialChaoshiQueryVo.getMaterialName()!=null&&materialChaoshiQueryVo.getMaterialName().trim().length()>0){
				hql.append(" and materialName like '%"+materialChaoshiQueryVo.getMaterialName()+"%'");
			}
			if(materialChaoshiQueryVo.getSjBeginDate()!=null&&materialChaoshiQueryVo.getSjBeginDate().trim().length()>0){
				hql.append(" and shelvesTime >= TO_DATE('"+materialChaoshiQueryVo.getSjBeginDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSjEndDate()!=null&&materialChaoshiQueryVo.getSjEndDate().trim().length()>0){
				hql.append(" and shelvesTime <= TO_DATE('"+materialChaoshiQueryVo.getSjEndDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSpecifications()!=null&&materialChaoshiQueryVo.getSpecifications().trim().length()>0){
				hql.append(" and specifications like '%"+materialChaoshiQueryVo.getSpecifications()+"%'");
			}
			if(materialChaoshiQueryVo.getSupplier()!=null&&materialChaoshiQueryVo.getSupplier().trim().length()>0){
				hql.append(" and supplier like '%"+materialChaoshiQueryVo.getSupplier()+"%'");
			}
			if(materialChaoshiQueryVo.getTexture()!=null&&materialChaoshiQueryVo.getTexture().trim().length()>0){
				hql.append(" and texture like '%"+materialChaoshiQueryVo.getTexture()+"%'");
			}
			if(materialChaoshiQueryVo.getUnitsId()!=null){
				hql.append(" and unitsId="+materialChaoshiQueryVo.getUnitsId());
			}
			if(materialChaoshiQueryVo.getCreateBeginTime()!=null&&materialChaoshiQueryVo.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+materialChaoshiQueryVo.getCreateBeginTime()+ " 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getCreateEndTime()!=null&&materialChaoshiQueryVo.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+materialChaoshiQueryVo.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getStatus()!=null&&materialChaoshiQueryVo.getStatus().trim().length()>0&&!materialChaoshiQueryVo.getStatus().equals("5")){
				hql.append(" and status ="+materialChaoshiQueryVo.getStatus());
			}
			if(materialChaoshiQueryVo.getChaoshiBeginTime()!=null&&materialChaoshiQueryVo.getChaoshiBeginTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') >= TO_DATE('"+materialChaoshiQueryVo.getChaoshiBeginTime()+ "','yyyy-mm')");
			}
			if(materialChaoshiQueryVo.getChaoshiEndTime()!=null&&materialChaoshiQueryVo.getChaoshiEndTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') <= TO_DATE('"+materialChaoshiQueryVo.getChaoshiEndTime()+"','yyyy-mm')");
			}
			
		}
		if(units==null){
			hql.append(" and status=1");
		}
		hql.append(" and exists(select 1 from Units u where u.unitsId=m.unitsId and u.funitsId="+materialChaoshiQueryVo.getFunitsId()+")");
		super.executeUpdate(hql.toString());
		return false;
	}
	@Override
	public boolean huituiAll(MaterialChaoshiQueryVo materialChaoshiQueryVo,
			Units units) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("update MaterialChaoshi m set status=2 where status=0  ");
		if(materialChaoshiQueryVo!=null){
			if(materialChaoshiQueryVo.getDrawingnum()!=null&&materialChaoshiQueryVo.getDrawingnum().trim().length()>0){
				hql.append(" and m.drawingnum like '%"+materialChaoshiQueryVo.getDrawingnum()+"%'");
			}
			if(materialChaoshiQueryVo.getFunitsId()!=null){
				hql.append(" and exists(select 1 from Units u where u.unitsId=m.unitsId and u.funitsId="+materialChaoshiQueryVo.getFunitsId()+")");
			}
			if(materialChaoshiQueryVo.getMaterialCode()!=null&&materialChaoshiQueryVo.getMaterialCode().trim().length()>0){
				hql.append(" and materialCode like '%"+materialChaoshiQueryVo.getMaterialCode()+"%'");
			}
			if(materialChaoshiQueryVo.getMaterialName()!=null&&materialChaoshiQueryVo.getMaterialName().trim().length()>0){
				hql.append(" and materialName like '%"+materialChaoshiQueryVo.getMaterialName()+"%'");
			}
			if(materialChaoshiQueryVo.getSjBeginDate()!=null&&materialChaoshiQueryVo.getSjBeginDate().trim().length()>0){
				hql.append(" and shelvesTime >= TO_DATE('"+materialChaoshiQueryVo.getSjBeginDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSjEndDate()!=null&&materialChaoshiQueryVo.getSjEndDate().trim().length()>0){
				hql.append(" and shelvesTime <= TO_DATE('"+materialChaoshiQueryVo.getSjEndDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSpecifications()!=null&&materialChaoshiQueryVo.getSpecifications().trim().length()>0){
				hql.append(" and specifications like '%"+materialChaoshiQueryVo.getSpecifications()+"%'");
			}
			if(materialChaoshiQueryVo.getSupplier()!=null&&materialChaoshiQueryVo.getSupplier().trim().length()>0){
				hql.append(" and supplier like '%"+materialChaoshiQueryVo.getSupplier()+"%'");
			}
			if(materialChaoshiQueryVo.getTexture()!=null&&materialChaoshiQueryVo.getTexture().trim().length()>0){
				hql.append(" and texture like '%"+materialChaoshiQueryVo.getTexture()+"%'");
			}
			if(materialChaoshiQueryVo.getUnitsId()!=null){
				hql.append(" and unitsId="+materialChaoshiQueryVo.getUnitsId());
			}
			if(materialChaoshiQueryVo.getCreateBeginTime()!=null&&materialChaoshiQueryVo.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+materialChaoshiQueryVo.getCreateBeginTime()+ " 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getCreateEndTime()!=null&&materialChaoshiQueryVo.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+materialChaoshiQueryVo.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getStatus()!=null&&materialChaoshiQueryVo.getStatus().trim().length()>0&&!materialChaoshiQueryVo.getStatus().equals("5")){
				hql.append(" and status ="+materialChaoshiQueryVo.getStatus());
			}
			if(materialChaoshiQueryVo.getChaoshiBeginTime()!=null&&materialChaoshiQueryVo.getChaoshiBeginTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') >= TO_DATE('"+materialChaoshiQueryVo.getChaoshiBeginTime()+ "','yyyy-mm')");
			}
			if(materialChaoshiQueryVo.getChaoshiEndTime()!=null&&materialChaoshiQueryVo.getChaoshiEndTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') <= TO_DATE('"+materialChaoshiQueryVo.getChaoshiEndTime()+"','yyyy-mm')");
			}
			
		}
		if(units==null){
			hql.append(" and status=1");
		}
		hql.append(" and exists(select 1 from Units u where u.unitsId=m.unitsId and u.funitsId="+units.getUnitsId()+")");
		super.executeUpdate(hql.toString());
		return false;
	}

	@Override
	public boolean shanchuAll(MaterialChaoshiQueryVo materialChaoshiQueryVo,
			Units units) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer("delete from  MaterialChaoshi m  where (status=0 or status=2)  ");
		if(materialChaoshiQueryVo!=null){
			if(materialChaoshiQueryVo.getDrawingnum()!=null&&materialChaoshiQueryVo.getDrawingnum().trim().length()>0){
				hql.append(" and m.drawingnum like '%"+materialChaoshiQueryVo.getDrawingnum()+"%'");
			}
			if(materialChaoshiQueryVo.getFunitsId()!=null){
				hql.append(" and exists(select 1 from Units u where u.unitsId=m.unitsId and u.funitsId="+materialChaoshiQueryVo.getFunitsId()+")");
			}
			if(materialChaoshiQueryVo.getMaterialCode()!=null&&materialChaoshiQueryVo.getMaterialCode().trim().length()>0){
				hql.append(" and materialCode like '%"+materialChaoshiQueryVo.getMaterialCode()+"%'");
			}
			if(materialChaoshiQueryVo.getMaterialName()!=null&&materialChaoshiQueryVo.getMaterialName().trim().length()>0){
				hql.append(" and materialName like '%"+materialChaoshiQueryVo.getMaterialName()+"%'");
			}
			if(materialChaoshiQueryVo.getSjBeginDate()!=null&&materialChaoshiQueryVo.getSjBeginDate().trim().length()>0){
				hql.append(" and shelvesTime >= TO_DATE('"+materialChaoshiQueryVo.getSjBeginDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSjEndDate()!=null&&materialChaoshiQueryVo.getSjEndDate().trim().length()>0){
				hql.append(" and shelvesTime <= TO_DATE('"+materialChaoshiQueryVo.getSjEndDate()+"','yyyy-mm-dd')");
			}
			if(materialChaoshiQueryVo.getSpecifications()!=null&&materialChaoshiQueryVo.getSpecifications().trim().length()>0){
				hql.append(" and specifications like '%"+materialChaoshiQueryVo.getSpecifications()+"%'");
			}
			if(materialChaoshiQueryVo.getSupplier()!=null&&materialChaoshiQueryVo.getSupplier().trim().length()>0){
				hql.append(" and supplier like '%"+materialChaoshiQueryVo.getSupplier()+"%'");
			}
			if(materialChaoshiQueryVo.getTexture()!=null&&materialChaoshiQueryVo.getTexture().trim().length()>0){
				hql.append(" and texture like '%"+materialChaoshiQueryVo.getTexture()+"%'");
			}
			if(materialChaoshiQueryVo.getUnitsId()!=null){
				hql.append(" and unitsId="+materialChaoshiQueryVo.getUnitsId());
			}
			if(materialChaoshiQueryVo.getCreateBeginTime()!=null&&materialChaoshiQueryVo.getCreateBeginTime().trim().length()>0){
				hql.append(" and createTime >= TO_DATE('"+materialChaoshiQueryVo.getCreateBeginTime()+ " 00:00:00','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getCreateEndTime()!=null&&materialChaoshiQueryVo.getCreateEndTime().trim().length()>0){
				hql.append(" and createTime <= TO_DATE('"+materialChaoshiQueryVo.getCreateEndTime()+" 23:59:59','yyyy-mm-dd hh24:mi:ss')");
			}
			if(materialChaoshiQueryVo.getStatus()!=null&&materialChaoshiQueryVo.getStatus().trim().length()>0&&!materialChaoshiQueryVo.getStatus().equals("5")){
				hql.append(" and status ="+materialChaoshiQueryVo.getStatus());
			}
			if(materialChaoshiQueryVo.getChaoshiBeginTime()!=null&&materialChaoshiQueryVo.getChaoshiBeginTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') >= TO_DATE('"+materialChaoshiQueryVo.getChaoshiBeginTime()+ "','yyyy-mm')");
			}
			if(materialChaoshiQueryVo.getChaoshiEndTime()!=null&&materialChaoshiQueryVo.getChaoshiEndTime().trim().length()>0){
				hql.append(" and TO_DATE(month,'yyyy-mm') <= TO_DATE('"+materialChaoshiQueryVo.getChaoshiEndTime()+"','yyyy-mm')");
			}
			
		}
		if(units==null){
			hql.append(" and status=1");
		}else{
			hql.append(" and unitsId="+units.getUnitsId());
		}
		super.executeUpdate(hql.toString());
		return false;
	}
}
